import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'
import { Observable } from 'rxjs'
import type { Request } from 'express'
import { Reflector } from '@nestjs/core'
@Injectable()
export class TigerGuard implements CanActivate {
  constructor(private Reflector: Reflector) {}

  canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
    const roles = this.Reflector.get<string[]>('role', context.getHandler())
    const req = context.switchToHttp().getRequest<Request>()
    console.log(roles, req.query.role)
    if (roles?.includes(req.query.role as string)) {
      console.log('有了')
      return true
    } else {
      console.log('没了')
      return false
    }
  }
}
